﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<CarHelpDesk.Web.Models.Question>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    <%= Html.Encode(Model.Title) %>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> 
 <% using (Ajax.BeginForm("Edit", "Questions", new { id = Model.ID }, new AjaxOptions()
       {
           HttpMethod = "POST",
           OnSuccess = "onQuestionEditSuccess",
           OnBegin = "onQuestionEditBegin",
           OnComplete = "onQuestionEditComplete"
       }, new { id = "submit_edit" }))
    {%>   
<script type="text/javascript">
    $(document).ready(function() {
            $('.question-edit-content').hide(); 
        });    

    function showEditMode() {
        $('.question-edit-content').show('slow');
        $('.question-content').hide();
        $('.question-images-content').hide(); 
        $('#edit_link').hide();        
    }

    function onQuestionEditSuccess(content) {
        $('.question-edit-content').hide('slow');
        $('.question-content').html(content.get_object().txtContentEdit);
        $('.question-content').show();
        $('#edit_link').show();
    }

    function onQuestionEditBegin(content) {
        $("#submit_edit").attr("disabled", true);
    }

    function onQuestionEditComplete(content) {
        $("#submit_edit").attr("disabled", false);
    }
</script>
    <div class="question">
        <div class="question-vote">
            <span id="question_vote_up" class="vote-icon vote-up" title="гласувай за" onclick="VoteForQuestion(<%= Html.Encode(Model.ID) %>,1)">
            </span><span id="question_rating" class="vote-count">
                <%= Html.Encode(Model.VoteUpCount - Model.VoteDownCount) %></span> <span id="question_vote_down"
                    class="vote-icon vote-down" title="гласувай против" onclick="VoteForQuestion(<%= Html.Encode(Model.ID) %>,-1)">
                </span>
        </div>
        <div>
            <div class="question-header">
                <span onclick="ToogleFavourite(<%=Html.Encode(Model.ID) %>)" id="favourite-question"
                    class="favourite-question-icon <%=((bool)ViewData["isFavourite"]) ? "favourite-question-yes" : "favourite-question-no"%>"
                    title="Отговорът е добавен в любими"></span>
                <%= Html.Encode(Model.Title)%>
            </div>        
            <div class="question-content">
                <%= Html.Encode(Model.Content)%>
            </div>
            <div class="question-edit-content">
                <br />
                <%= Html.TextArea("txtContentEdit", Model.Content, 5, 20, null)%>
                <%= Html.ValidationMessageFor(model => model.Content)%>
                <br />
                <input id="submit_edit" type="submit" value="Промени" style="width:100px;"/> 
            </div>  
            <br />
            <div style="margin-left:40px;"><%= Html.LabelFor(model => model.aspnet_User)%>: <%= Html.Encode(Model.aspnet_User.UserName)%></div>
            <div style="margin-left:40px;"><%= Html.LabelFor(model => model.CreateDate)%>: <%= Html.Encode(String.Format("{0:g}", Model.CreateDate))%></div>
            
            <% if (User.IsInRole("Moderator") || User.IsInRole("MegaModerator"))
               {%>
            <div class="float-right">  
                <b><a href="#" id="edit_link" onclick="showEditMode()">Промени</a></b>
                
                <% if (User.IsInRole("Moderator"))
                       {%>
                <b><a href='<%= Url.Action("Delete", "Questions", new { id = Model.ID}) %>' onclick="return confirm('Сигурни ли сте, че искате да направите неактивен този въпрос?');">Изтрий</a></b>
                <% } %>
                
                <% else { %>
                <b><a href='<%= Url.Action("MegaModeratorDelete", "Questions", new { id = Model.ID}) %>' onclick="return confirm('Сигурни ли сте, че искате да изтриете този въпрос?');">Изтрий</a></b>
                <% if (Model.Active == false) 
                   {%>
                <b><a href='<%= Url.Action("MegaModeratorRevert", "Questions", new {id = Model.ID}) %>' onclick="return confirm('Сигурни ли сте, че искате да направите активен този въпрос?');">Върни в списъка с въпроси</a></b>
                <% } %>
                
                <% } %>
                
            </div>
            <% } %>
  <% } %>      
 <% Html.RenderAction("IndexQuestion", "Tags", new { questionID = Model.ID });%>      
 <%--
        <div class="question-images-content">
            <%= ViewData["tableImages"] %>
        </div> --%>
     </div>        


        <div class="footer">
            <%--TODO: check for role--%>
            <span id="FlaggQuestion" class="flagg-post-icon <%=((bool)ViewData["isFlagged"]) ? "flagg-post-yes" : "flagg-post-no"%>" onclick="FlagQuestion(<%= Html.Encode(Model.ID) %>)">
            </span>
        </div>
    </div>
    <%= Html.Action("Index", "Answers", new {questionID = Model.ID })%>

    <%= Html.Action("Create", "Answers", new {questionID = Model.ID })%>
</asp:Content>
